﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace hse_2013_project
{
    /// <summary>
    /// Класс отрисовки змеи
    /// </summary>
    public class Snake
    {
        private Rectangle[] snakeRec;
        private SolidBrush brush, brush2;
        private int x, y, width, height;
        public Rectangle[] SnakeRec
        {
            get { return snakeRec; }


        }

        public Snake()
        {
            snakeRec = new Rectangle[3];
            Random r = new Random();


            x = 20;
            y = 24;
            width = 10;
            height = 10;
            for (int i = 0; i < snakeRec.Length; i++)
            {

                snakeRec[i] = new Rectangle(x, y, width, height);
                x -= 10;
            }
        }
        /// <summary>
        /// Метод раскраски змеи
        /// </summary>
        /// <param name="e"></param>
        public void drawSnake(Graphics e)
        { 
            brush = new SolidBrush(Color.Red);
            brush2 = new SolidBrush(Color.Yellow);
           
            for (int i = 0; i < snakeRec.Length; i++)
            {
                if(i%2==0) e.FillRectangle(brush, snakeRec[i]);
                else e.FillRectangle(brush2, snakeRec[i]);
            }
               
         
        }
        /// <summary>
        /// Метод перерисовки змеи при движении
        /// </summary>
        public void DrawSnake()
        {
            for (int i = snakeRec.Length - 1; i > 0; i--)
            {
                snakeRec[i] = snakeRec[i - 1];
            }
        }
        /// <summary>
        /// Метод сдвига вниз
        /// </summary>
        public void moveDown()
        {
            DrawSnake();
            snakeRec[0].Y += 10;
        }
        /// <summary>
        /// Метод перемещения наверх
        /// </summary>
        public void moveUp()
        {
            DrawSnake();
            snakeRec[0].Y -= 10;
        }
        /// <summary>
        /// Метод движения влево
        /// </summary>
        public void moveLeft()
        {
            DrawSnake();
            snakeRec[0].X -= 10;
        }
        /// <summary>
        /// Метод передвижения вправо
        /// </summary>
        public void moveRight()
        {
            DrawSnake();
            snakeRec[0].X += 10;
        }
        /// <summary>
        /// Метод увеличения длины змеи
        /// </summary>
        public void growSnake()
        {
            List<Rectangle> rec = snakeRec.ToList();
            rec.Add(new Rectangle(snakeRec[snakeRec.Length - 1].X, snakeRec[snakeRec.Length - 1].Y, width, height));
            snakeRec = rec.ToArray();

        }

    }
   
}
